package com.sdkj.dspservice.common.react;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sdkj.dspservice.common.base.entity.BaseResult;
import lombok.Data;

/**
 *  antdPro返回类
 * @author Administrator
 */
@Data
public class AntdProResult extends BaseResult {

    /**
     * 校验错误码
     */
    public static final int VALIDATOR_ERROR = 400;
    public static final int SYSTEM_ERROR = 500;

    /**
     * 是否请求成功
     */
    private Boolean success;
    /**
     * 错误码
     */
    private int errorCode;
    /**
     * 展示类型
     */
    private int showType;
    /**
     * 总数
     */
    private long total;
    /**
     * wangeditor所需要的errno
     */
    protected String errno;


    public AntdProResult() {
        success = true;
    }

    @Override
    public AntdProResult success(Object data) {
        success = true;
        errno = "0";
        super.success(data);
        return this;
    }

    public void success(IPage page) {
        success = true;
        errno = "0";
        total = page.getTotal();
        data = page.getRecords().toArray();
    }

    @Override
    public void success(Object data, String msg) {
        success = true;
        errno = "0";
        super.success(data, msg);
    }

    public void error(int errorCode) {
        success = false;
        this.errorCode = errorCode;
    }

    public void error(int errorCode, String errorMsg) {
        success = false;
        this.errorCode = errorCode;
        errorMessage = errorMsg;
    }

}
